function getVcode(){
    $.ajax({
        type:"post",
        url:"/adminLogin/vcode",
        success:function(data){
            if(data.code!=0){
                $("#yzm").attr('src',data.path)
            }
        }
    })
}
$('#Commonheader').load('/pc/Commonheader.html');
$('#Commonfooter').load('/pc/CommonFooter.html');

$(function(){

	
	
    "use strict";
    getVcode();
    $("#yzm").on("click",function(){
        getVcode();
    })
    
    var pp = window.sessionStorage['pp'];
    var cxmz = window.sessionStorage['cxmz'];
    var cx = window.sessionStorage['cx'];
    var pfbz = window.sessionStorage['pfbz'];
    var ccrq = window.sessionStorage['ccrq'];
    var cjmc = window.sessionStorage['cjmc'];
    var xcj = window.sessionStorage['xcj'];
    
    var cx_main_listHTML = `
		    <li>
			    <div>
			        <i class="cx_main_logo"></i>
			        <span class="cx_main_tip">品牌</span>
			        <span class="cx_main_section">${pp}</span>
			    </div>
			    <div>
			        <i class="cx_main_logo"></i>
			        <span class="cx_main_tip">车系名称</span>
			        <span class="cx_main_section">${cxmz}</span>
			    </div>
			</li>
			<li>
			    <div>
			        <i class="cx_main_logo"></i>
			        <span class="cx_main_tip">车型</span>
			        <span class="cx_main_section">${cx}</span>
			    </div>
			    <div>
			        <i class="cx_main_logo"></i>
			        <span class="cx_main_tip">排放标准</span>
			        <span class="cx_main_section">${pfbz}</span>
			    </div>
			</li>
			<li>
			    <div>
			        <i class="cx_main_logo"></i>
			        <span class="cx_main_tip">出厂日期</span>
			        <span class="cx_main_section">${ccrq}</span>
			    </div>
			    <div>
			        <i class="cx_main_logo"></i>
			        <span class="cx_main_tip">厂家名称</span>
			        <span class="cx_main_section">${cjmc}</span>
			    </div>
			</li>
			<li>
			    <div>
			        <i class="cx_main_logo"></i>
			        <span class="cx_main_tip">新车价</span>
			        <span class="cx_main_section">${xcj}</span>
			    </div>
			</li>
    `;
    $('#cx_main_list').html(cx_main_listHTML);
    
  //table内容向上滚动轮播
	var area =document.getElementById('scrollBox');
	var con1 = document.getElementById('con1');
	var con2 = document.getElementById('con2');
	con2.innerHTML=con1.innerHTML;
	function scrollUp(){
	    if(area.scrollTop>=con1.offsetHeight){
	        area.scrollTop=0;
	    }else{
	        area.scrollTop++
	    }
	}
	var time = 50;
	var mytimer=setInterval(scrollUp,time);
	area.onmouseover=function(){
	    clearInterval(mytimer);
	}
	area.onmouseout=function(){
	    mytimer=setInterval(scrollUp,time);
	}
    
	/**
     * 车架号格式验证
     * */
    $('#vinNum').blur(function(){
    	var vin = $('#vinNum').val();
    	var vinReg = /^[A-Za-z0-9]{17}$/;
    	if( vinReg.test(vin) == false ){
			$('#vinNum').addClass('err');
			$('#vinNum').val('');
			$('#vinNum').attr('placeholder','您输入的号码有误');
    	}else{
    		$('#vinNum').removeClass('err');
    	}
    })
    $('#vinNum').focus(function(){
    	$('#vinNum').removeClass('err');
		$('#vinNum').attr('placeholder','请输入VIN号');
		getVcode();
    })
    
    
    $('#cxcx_btn>p').click(function(){
        var vinS =$('#vinNum').val();
        var vcodeS = $('#vcode').val();
        
        if( vinS != '' && vinS != undefined && vinS != null && vcodeS != '' && vcodeS != undefined && vcodeS != null){
        	$.ajax({
                url:'/che300/identifyModelByVIN',
                type:'get',
                data:{
                	vin:vinS,
                	vcode:vcodeS
                },
                success:function(data){
                	console.log(data);
             	   if(data.ret_code == 1){
             		  var pp = data.series_name;
                      var cxmz = data.series_name;
                      var cx = data.model_name;
                      var pfbz = data.model_emission_standard;
                      var ccrq = data.model_year;
                      var cjmc = data.brand_name;
                      var xcj = data.model_price;
                      
                      var cx_main_listHTML = `
                  		    <li>
                  			    <div>
                  			        <i class="cx_main_logo"></i>
                  			        <span class="cx_main_tip">品牌</span>
                  			        <span class="cx_main_section">${pp}</span>
                  			    </div>
                  			    <div>
                  			        <i class="cx_main_logo"></i>
                  			        <span class="cx_main_tip">车系名称</span>
                  			        <span class="cx_main_section">${cxmz}</span>
                  			    </div>
                  			</li>
                  			<li>
                  			    <div>
                  			        <i class="cx_main_logo"></i>
                  			        <span class="cx_main_tip">车型</span>
                  			        <span class="cx_main_section">${cx}</span>
                  			    </div>
                  			    <div>
                  			        <i class="cx_main_logo"></i>
                  			        <span class="cx_main_tip">排放标准</span>
                  			        <span class="cx_main_section">${pfbz}</span>
                  			    </div>
                  			</li>
                  			<li>
                  			    <div>
                  			        <i class="cx_main_logo"></i>
                  			        <span class="cx_main_tip">出厂日期</span>
                  			        <span class="cx_main_section">${ccrq}</span>
                  			    </div>
                  			    <div>
                  			        <i class="cx_main_logo"></i>
                  			        <span class="cx_main_tip">厂家名称</span>
                  			        <span class="cx_main_section">${cjmc}</span>
                  			    </div>
                  			</li>
                  			<li>
                  			    <div>
                  			        <i class="cx_main_logo"></i>
                  			        <span class="cx_main_tip">新车价</span>
                  			        <span class="cx_main_section">${xcj}</span>
                  			    </div>
                  			</li>
                      `;
                      $('#cx_main_list').html(cx_main_listHTML);
             	   }else{
             		   
             		  if(data.ret_msg == '查询失败'){
	             			$('#vinNum').addClass('err');
	 	        			$('#vinNum').val('');
	 	        			$('#vinNum').attr('placeholder','您输入的号码有误');
	 	        			$('#vinNum').focus(function(){
	 	        		    	$('#vinNum').removeClass('err');
	 	        				$('#vinNum').attr('placeholder','请输入VIN号');
	 	        				getVcode();
	 	        		    })
	               	   }else{
	               		   $('#vcode').addClass('err');
	               		   $('#vcode').parent().addClass('err');
	  	           			$('#vcode').val('');
	  	           			$('#vcode').attr('placeholder','验证码错误');
	  	           			$('#vcode').focus(function(){
	  	           		    	$('#vcode').removeClass('err');
	  	           		    	$('#vcode').parent().removeClass('err');
	  	           				$('#vcode').attr('placeholder','请输入验证码');
	  	           				getVcode();
	  	           		    })
	               	   }
             		   
             	   }
                	
                }
            })
        }else{
        	console.log(1);
        	$('#vcode').addClass('err');
			$('#vcode').val('');
			$('#vcode').attr('placeholder','验证码错误');
        }
        
        
    })
})